package com.jy.admin.rest;

import com.jsoniter.output.JsonStream;
import com.jy.admin.annotations.AdminSignIgnore;
import com.jy.admin.auth.anno.VisitorAccessible;
import com.jy.admin.db.dao.CeAgentAccountDao;
import com.jy.admin.db.entity.CeAgentAccountEntity;
import com.jy.admin.jobs.SyncCommentsJob;
import com.jy.admin.services.cashPocket.CashPocketService;
import com.jy.admin.services.cashPocket.CredexPressService;
import com.jy.admin.services.cashPocket.RupeeGoService;
import com.jy.admin.services.cashPocket.vo.RepaymentLinkVo;
import com.jy.admin.utils.HttpClient2;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.*;


/**
 * Created with IntelliJ IDEA.
 * User: binary (mr.vencnet@gmail.com)
 * Date: 2020-06-02
 * Time: 17:18
 */
@RestController
@RequestMapping("/test")
public class TestController {

    private static final Logger LOGGER = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private CeAgentAccountDao agentAccountDao;

    @Autowired
    private CashPocketService cashPocketService;

    @Autowired
    private SyncCommentsJob syncCommentsJob;

    @Autowired
    private CredexPressService credexPressService;

    @Autowired
    private HttpClient2 httpClient2;

    @Autowired
    private RupeeGoService rupeeGoService;

    @AdminSignIgnore
    @RequestMapping("/rb")
    @VisitorAccessible
    public String okup111() {
        String repaymentLinkVo = rupeeGoService.updateRepaymentLink("238437384696373730TD",false);
        return JsonStream.serialize(repaymentLinkVo);
    }

    @AdminSignIgnore
    @RequestMapping("/up1")
    @VisitorAccessible
    public String okup11(@RequestParam("DropOrder") Object DropOrder, @RequestParam("fileName") MultipartFile upload) {
        return "a";
    }

    @AdminSignIgnore
    @RequestMapping("/up")
    @VisitorAccessible
    public String okup() {

        return "ok";
    }

    public static void main(String[] args) {
        Document parse = Jsoup.parse("\n" +
                "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head>    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />    <meta http-equiv=\"x-ua-compatible\" content=\"ie=7\" />    <title></title>    <meta name=\"csrf-param\" content=\"_csrf\"><meta name=\"csrf-token\" content=\"HoAZXLUCAq0W8wxNJ48O8VUnvcZVakYYOmzrJ39yuDpk0VMW4Vdr91m0XSxF6HmheFDYnjwwFXl8H9NqGjfQQA==\">    <link href=\"/image/admincp.css?1642424926\" rel=\"stylesheet\" type=\"text/css\" />    <link href=\"/css/site.css?1642424926\" rel=\"stylesheet\" type=\"text/css\" />    <link rel=\"shortcut icon\" href=\"/image/xiao.ico\" type=\"image/x-icon\" /></head><body                style=\"background-image: url( https://ok-call.moneywoods.in/index.php?r=main%2Fwater)\"><script type=\"text/JavaScript\">    var admincpfilename = 'index.php', IMGDIR = 'image/', STYLEID = '1', VERHASH = 'dob', IN_ADMINCP = true, ISFRAME = '0', STATICURL='./', SITEURL = '', JSPATH = 'js/';</script><script src=\"/js/admin.js?1642424926\" type=\"text/javascript\"></script><script src=\"/js/jquery.min.js\" type=\"text/javascript\"></script><div id=\"append_parent\"></div><div id=\"ajaxwaitid\"></div><div class=\"container\" id=\"cpcontainer\">    <h3>提示</h3><div class=\"infobox\">\t<h4 class=\"infotitle3\">The UTR corresponding to this order is being processed, please do not add repeatedly</h4>\t<p class=\"marginbot\">\t\t\t\t<script type=\"text/javascript\">\t\tif(history.length > 0) document.write('<a href=\"javascript:history.go(-1);\" class=\"lightlink\">点击这里返回上一页</a>');\t\t</script>\t\t\t</p></div></div></body></html>");

        Elements h4 = parse.select("h4");
        String msg = h4.get(0).text().toString();
        System.err.println(111);

    }


    @AdminSignIgnore
    @RequestMapping("/refresh")
    @VisitorAccessible
    public String ok() {
        List<CeAgentAccountEntity> credexpress = agentAccountDao.getAccountsMerchantCode("credexpress");
        credexpress.forEach(agentAccount -> {
            credexPressService.refresh(agentAccount);
        });
        return "ok";
    }

    @AdminSignIgnore
    @RequestMapping("/compose")
    @VisitorAccessible
    public String ok1() {

        List<CeAgentAccountEntity> credexpress = agentAccountDao.getAccountsMerchantCode("credexpress");
        credexpress.forEach(agentAccount -> {
            credexPressService.compostCollectionData(agentAccount);
        });
        return "ok";
    }

    @AdminSignIgnore
    @RequestMapping("/push")
    @VisitorAccessible
    public String ok11() {
        List<CeAgentAccountEntity> credexpress = agentAccountDao.getAccountsMerchantCode("credexpress");
        credexpress.forEach(agentAccount -> {
            credexPressService.pushDataToCollection(agentAccount);
        });
        return "ok";
    }

    @AdminSignIgnore
    @RequestMapping("/update")
    @VisitorAccessible
    public String ok1122() {
        List<CeAgentAccountEntity> credexpress = agentAccountDao.getAccountsMerchantCode("credexpress");
        credexpress.forEach(agentAccount -> {
            credexPressService.updatePaidOrderToCollection(agentAccount);
        });
        return "ok";
    }
    @AdminSignIgnore
    @RequestMapping("/check")
    @VisitorAccessible
    public String check() {
        List<CeAgentAccountEntity> credexpress = agentAccountDao.getAccountsMerchantCode("credexpress");
        credexpress.forEach(agentAccount -> {
            credexPressService.checkOrdersPaidStatus(agentAccount);
        });
        return "ok";
    }

    @AdminSignIgnore
    @RequestMapping("/comments")
    @VisitorAccessible
    public String ok111() {
        syncCommentsJob.syncComment();
        return "ok";
    }

    @AdminSignIgnore
    @RequestMapping("/comments/sync")
    @VisitorAccessible
    public String ok11112() {
        syncCommentsJob.sendLog();
        return "ok";
    }


}
